Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add traceID if possible when using context logger. #2518

Merged
merged 3 commits into from
Apr 24, 2020

Conversation

cyriltovena
Copy link
Contributor

This change the behaviour of the context logger, there is situation where we don't have an org_id and we would still want to log with the spanID.

I'm also renaming span_id to spanID because we have inconsistency with weaveworks server which uses spanID. Wasn't sure if this would be welcomed change in weaveworks but I'm can send the PR there.

Signed-off-by: Cyril Tovena cyril.tovena@gmail.com

@cyriltovena
Copy link
Contributor Author

Need rebase on #2521 once merged.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
@pracucci
Copy link
Contributor

I've pushed a commit to rebase master.

@@ -127,7 +129,7 @@ func WithUserID(userID string, l log.Logger) log.Logger {
// its details.
func WithTraceID(traceID string, l log.Logger) log.Logger {
// See note in WithContext.
return log.With(l, "trace_id", traceID)
return log.With(l, "traceID", traceID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also renaming span_id to spanID because we have inconsistency with weaveworks server which uses spanID.

Note to myself: I guess you meant traceID and not spanID.

pkg/util/log.go Outdated
Comment on lines 106 to 111
if err != nil {
if err != nil && err != user.ErrNoOrgID {
return l
}
l = WithUserID(userID, l)
if err == nil {
l = WithUserID(userID, l)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we simplify it as the following, so that the trace ID is injected in any case?

if err == nil {
    l = WithUserID(userID, l)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, let's do that.

@pstibrany
Copy link
Contributor

I'm also renaming span_id to spanID because we have inconsistency with weaveworks server which uses spanID. Wasn't sure if this would be welcomed change in weaveworks but I'm can send the PR there.

For reference:

func (l Log) logWithRequest(r *http.Request) logging.Interface {

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
@pracucci pracucci merged commit 0bc9382 into cortexproject:master Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants